package cn.wolfcode.luowowo.exception;

import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理器
 *
 */
@ControllerAdvice//对controller进行加强
public class CommonExceptionHandler {
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public JsonResult logicExceptionHandler(Exception e) {
        e.printStackTrace();
        return JsonResult.error(JsonResult.CODE_ERROR, e.getMessage(), null);
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResult exceptionHandler(Exception e) {
        e.printStackTrace();
        return JsonResult.error(JsonResult.CODE_NETERROR, JsonResult.MSG_NETERROR, null);
    }
}
